package com.ruoyi.web.controller.docs;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.docs.domain.BizColumn;
import com.ruoyi.docs.service.IBizColumnService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 栏目Controller
 * 
 * @author ruoyi
 * @date 2024-05-05
 */
@RestController
@RequestMapping("/docs/column")
public class BizColumnController extends BaseController
{
    @Autowired
    private IBizColumnService bizColumnService;

    /**
     * 查询栏目列表
     */
    @PreAuthorize("@ss.hasPermi('docs:column:list')")
    @GetMapping("/list")
    public AjaxResult list(BizColumn bizColumn)
    {
        List<BizColumn> list = bizColumnService.selectBizColumnList(bizColumn);
        return success(list);
    }

    /**
     * 导出栏目列表
     */
    @PreAuthorize("@ss.hasPermi('docs:column:export')")
    @Log(title = "栏目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizColumn bizColumn)
    {
        List<BizColumn> list = bizColumnService.selectBizColumnList(bizColumn);
        ExcelUtil<BizColumn> util = new ExcelUtil<BizColumn>(BizColumn.class);
        util.exportExcel(response, list, "栏目数据");
    }

    /**
     * 获取栏目详细信息
     */
    @PreAuthorize("@ss.hasPermi('docs:column:query')")
    @GetMapping(value = "/{columnId}")
    public AjaxResult getInfo(@PathVariable("columnId") Long columnId)
    {
        return success(bizColumnService.selectBizColumnByColumnId(columnId));
    }

    /**
     * 新增栏目
     */
    @PreAuthorize("@ss.hasPermi('docs:column:add')")
    @Log(title = "栏目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizColumn bizColumn)
    {
        bizColumn.setCreateBy(getUsername());
        return toAjax(bizColumnService.insertBizColumn(bizColumn));
    }

    /**
     * 修改栏目
     */
    @PreAuthorize("@ss.hasPermi('docs:column:edit')")
    @Log(title = "栏目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizColumn bizColumn)
    {
        bizColumn.setUpdateBy(getUsername());
        return toAjax(bizColumnService.updateBizColumn(bizColumn));
    }
    @PreAuthorize("@ss.hasPermi('docs:column:edit')")
    @Log(title = "栏目", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody BizColumn bizColumn)
    {
        bizColumn.setUpdateBy(getUsername());
        return toAjax(bizColumnService.updateBizColumn(bizColumn));
    }
    /**
     * 删除栏目
     */
    @PreAuthorize("@ss.hasPermi('docs:column:remove')")
    @Log(title = "栏目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{columnIds}")
    public AjaxResult remove(@PathVariable Long[] columnIds)
    {
        return toAjax(bizColumnService.deleteBizColumnByColumnIds(columnIds));
    }
}
